import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/models/response/other_user_info.dart';
import 'package:sainbainu/common/values/sizes.dart';

import '../index.dart';

/// hello
class CustomSliverAppBar extends GetView<UserDetailController> {
  final Widget headContent;
  final Widget? titleChild;
  final PreferredSizeWidget? bottom;
  final VoidCallback? onBack;
  final OtherUserInfoResponse userInfo;

  const CustomSliverAppBar({
    Key? key,
    required this.headContent,
    this.titleChild,
    required this.userInfo,
    this.bottom,
    this.onBack,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return _buildSliverAppBar();
  }

  /// 头部
  _buildSliverAppBar() {
    return SliverAppBar(
      leading: Obx(
        () => IconButton(
          onPressed: onBack,
          icon: Icon(
            Icons.arrow_back_ios_new_rounded,
            color: controller.state.isCollapsed.value
                ? Colors.black
                : Colors.white,
          ),
        ),
      ),
      title: Obx(
        () => Opacity(
          opacity: controller.state.titleOpacity.value,
          child: titleChild,
        ),
      ),
      pinned: true,
      stretch: true,
      expandedHeight: kProfileCoverHeight,
      flexibleSpace: FlexibleSpaceBar(
        collapseMode: CollapseMode.parallax,
        background: headContent,
      ),
      bottom: bottom,
    );
  }
}
